﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HousingInfo.Library;

namespace WebHousingInfo.Admin
{
    public partial class CauHinh : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getoption();
            }
        }

        public void getoption()
        {
            try
            {
                txtngayxoahethan.Text = OptionBO.GetNameOptionBO("tudongxoatinhethan").OptionValue;
                cbautosms.Checked = Convert.ToBoolean(OptionBO.GetNameOptionBO("tudongcapnhatsms").OptionValue);
                if (OptionBO.GetNameOptionBO("tudongduyettinmoi").OptionValue == "True")
                {
                    dlautoapprove.SelectedValue = "tudong";
                }
                else
                {
                    dlautoapprove.SelectedValue = "tay";
                }
                if (OptionBO.GetNameOptionBO("tudongduyettinduan").OptionValue == "True")
                {
                    dlduan.SelectedValue = "tudong";
                }
                else
                {
                    dlduan.SelectedValue = "tay";
                }
                if (OptionBO.GetNameOptionBO("tudongduyettinvanban").OptionValue == "True")
                {
                    dlvanban.SelectedValue = "tudong";
                }
                else
                {
                    dlvanban.SelectedValue = "tay";
                }
                if (OptionBO.GetNameOptionBO("tudongduyettinDoanhnghiep").OptionValue == "True")
                {
                    dldoanhnghiep.SelectedValue = "tudong";
                }
                else
                {
                    dldoanhnghiep.SelectedValue = "tay";
                }
                txtngayxoaqc.Text = OptionBO.GetNameOptionBO("ngayxoavitriquangcao").OptionValue;
                cbarea.Checked = Convert.ToBoolean(OptionBO.GetNameOptionBO("hienthitenduong").OptionValue);
                txtsoluongtrangchu.Text = OptionBO.GetNameOptionBO("soluongtinnhadattrangchu").OptionValue;
                txtquangcaotren.Text = OptionBO.GetNameOptionBO("SoViTriQCTren").OptionValue;
                txtquangcaotrai.Text = OptionBO.GetNameOptionBO("SoViTriQCTrai").OptionValue;
                txtquangcaphai.Text = OptionBO.GetNameOptionBO("SoViTriQCPhai").OptionValue;
                txtgiahannhadat.Text = OptionBO.GetNameOptionBO("SoLanGiaHanTinNhaDat").OptionValue;
                txtgiahandoanhnghiep.Text = OptionBO.GetNameOptionBO("SoLanGiaHanTinDoanhNghiep").OptionValue;
            }
            catch
            { }
        }

        protected void btncapnhat_Click(object sender, EventArgs e)
        {
            OptionBO optionbo;
            try
            {
                optionbo = OptionBO.GetNameOptionBO("tudongxoatinhethan");
                optionbo.OptionValue = txtngayxoahethan.Text;
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("tudongduyettinmoi");
                if(dlautoapprove.SelectedValue == "tudong")
                {
                    optionbo.OptionValue = "True";
                }
                else
                {
                    optionbo.OptionValue = "False";
                }
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("tudongduyettinduan");
                if (dlduan.SelectedValue == "tudong")
                {
                    optionbo.OptionValue = "True";
                }
                else
                {
                    optionbo.OptionValue = "False";
                }
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("tudongduyettinvanban");
                if (dlvanban.SelectedValue == "tudong")
                {
                    optionbo.OptionValue = "True";
                }
                else
                {
                    optionbo.OptionValue = "False";
                }
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("tudongduyettinDoanhnghiep");
                if (dldoanhnghiep.SelectedValue == "tudong")
                {
                    optionbo.OptionValue = "True";
                }
                else
                {
                    optionbo.OptionValue = "False";
                }
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("tudongcapnhatsms");
                optionbo.OptionValue = cbautosms.Checked.ToString();
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("ngayxoavitriquangcao");
                optionbo.OptionValue = txtngayxoaqc.Text;
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("hienthitenduong");
                optionbo.OptionValue = cbarea.Checked.ToString();
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("soluongtinnhadattrangchu");
                optionbo.OptionValue = txtsoluongtrangchu.Text;
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("SoViTriQCTren");
                optionbo.OptionValue = txtquangcaotren.Text;
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("SoViTriQCTrai");
                optionbo.OptionValue = txtquangcaotrai.Text;
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("SoViTriQCPhai");
                optionbo.OptionValue = txtquangcaphai.Text;
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("SoLanGiaHanTinNhaDat");
                optionbo.OptionValue = txtgiahannhadat.Text;
                optionbo.Save();

                optionbo = OptionBO.GetNameOptionBO("SoLanGiaHanTinDoanhNghiep");
                optionbo.OptionValue = txtgiahandoanhnghiep.Text;
                optionbo.Save();

                pn_result.Visible = true;
                lblthongbao.Text = "Cập nhật thành công";
            }
            catch {
                pn_result.Visible = true;
                lblthongbao.Text = "Cập nhật thất bại";
            }
        }
    }
}
